package algocasts;

public class P36_binarySearch {
    public int binarySearch(int[] nums, int target) {
        if (nums == null) return -1;
        int low = 0, high = nums.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (nums[mid] < target) high = mid - 1;
            else if (nums[mid] > target) low = mid + 1;
            else return mid;
        }
        return -1;
    }
}
